home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
LOGIC Apps
/
Logic-APPLE_II_APPS.iso
/
pc
/
LOGIC Apple II 5.25" Library - DOS Part 3
/
DOS069.dsk
/
FRENCH MILITARY GAME.bas
< prev
next >
Wrap
BASIC Source File
|
2012-02-16
|
9KB
|
240 lines
5 DEF FN P(X) = 2 ^(X -1)
10 DIM S(165),R(30,2),L(11,11),W(3),A(165,11)
15 REM FRENCH MILITARY GAME, SIXTH BOOK OF MATHEMATICAL GAMES FROM SCIENTIFIC AMERICAN BY MARTIN GARDNER
20 REM INCORPORATES MATCH. LEARNING FROM UNEXPECTED HANGING BY MARTIN GARDNER
25 REM PROGRAMMED BY G.H. HERD SEPT.78 PUBLISHED IN CREATIVE COMPUTING SEPT.79
30 TEXT : HOME
35 VTAB 10: HTAB 9
40 PRINT "THE FRENCH MILITARY GAME"
42 PRINT
44 HTAB 9
45 PRINT " BY MARTIN GARDNER"
75 LET I = 1
80 FOR L = 1 TO 9
90 LET L1 = FN P(L)
100 FOR M = L +1 TO 10
110 LET M1 = FN P(M)
120 FOR R = M +1 TO 11
130 LET S(I) = L1 +M1 +( FN P(R))
140 LET I = I +1
150 NEXT R
160 NEXT M
170 NEXT L
175 HOME : VTAB 12: PRINT "DO YOU NEED INSTRUCTIONS? ";: INPUT IN$: IF LEFT$(IN$,1) < >"N" THEN GOSUB 12000
180 REM LOAD UP LEARNING CURVE
190 REM DISK COMMAND "LOAD DATA #5,34,A
200 FOR I = 1 TO 30
210 FOR J = 1 TO 2
220 LET R(I,J) = 0
230 NEXT J
240 NEXT I
250 FOR I = 1 TO 11
260 FOR J = 1 TO 11
270 READ L(I,J)
280 NEXT J
290 NEXT I
300 REM L(I,J)=0 MEANS MOVE I TO J NOT LEGAL
310 REM L(I,J)=1 MEANS MOVE I TO J LEGAL BLACK ONLY
320 REM L(I,J)=2 MEANS MOVE I TO J LEGAL FOR BOTH
330 REM
340 LET B = 6
350 LET W(1) = 1
360 LET W(2) = 2
370 LET W(3) = 4
380 LET I0 = 1
390 GOSUB 3000
490 GOSUB 10000
500 REM MAIN PROGRAM LOOP
510 PRINT "WHITE PEICES ARE AT ";W(1);" ";W(2);" ";W(3)
520 PRINT "THE BLACK PIECE IS AT ";B
530 PRINT "YOUR MOVE, FROM-TO X,Y ";
540 INPUT X,Y
545 IF X = 0 AND Y = 0 THEN 730
550 REM WAS IT A LEGAL MOVE
560 GOSUB 2000
570 IF L2 = 1 THEN 600
580 PRINT "FOUL !!!!!<CTRL-G><CTRL-G> TRY AGAIN."
590 GOTO 510
600 REM LEGAL MOVE - WHAT IS WHITE POSITION INDEX (S3)
602 COLOR= 3: ON X GOSUB 11001,11002,11003,11004,11005,11006,11007,11008,11009,11010,11011
604 COLOR= 15: ON Y GOSUB 11001,11002,11003,11004,11005,11006,11007,11008,11009,11010,11011
610 GOSUB 3000
615 IF I0 < = 19 THEN 630
620 PRINT "THAT'S 20 MOVES, ACE<CTRL-G>, AND YOU HAVEN'T TRAPPED ME."
621 GOTO 730
622 REM WHAT IS BLACK'S BEST MOVE - IF ANY
630 GOSUB 4000
640 IF M4 = 0 THEN 760
650 REM COMPUTER MOVES
660 PRINT "I MOVE TO ";M4
662 COLOR= 3: ON B GOSUB 11001,11002,11003,11004,11005,11006,11007,11008,11009,11010,11011
664 COLOR= 0: ON M4 GOSUB 11001,11002,11003,11004,11005,11006,11007,11008,11009,11010,11011
670 LET R(I0,1) = S3
680 LET R(I0,2) = M4
690 LET B = M4
700 LET I0 = I0 +1
710 IF B < >1 THEN 500
720 REM HERE ONLY IF MACHINE WINS
730 PRINT "I WIN<CTRL-G>.<CTRL-G>.<CTRL-G>.<CTRL-G>.<CTRL-G>.<CTRL-G>."
740 LET W = 1
750 GOTO 780
760 PRINT "<CTRL-G>I LOST......"
770 LET W = -1
780 REM UPDATE ARRAY A
790 GOSUB 6000
800 PRINT "WANT TO PLAY AGAIN? ";
810 INPUT Z$
820 IF LEFT$(Z$,1) = "Y" THEN 340
830 REM DISK COMMAND "STORE DATA #5,34,A"
840 STOP
2000 REM CHECK WHITES MOVE FOR LEGALITY
2030 LET L2 = -1
2040 FOR I2 = 1 TO 3
2050 LET J2 = I2
2060 IF W(I2) = X THEN 2100
2070 NEXT I2
2080 REM NO WHITE PIECE AT X
2090 GOTO 2200
2100 REM IF BLACK IS AT Y THEN ILLEGAL
2110 IF B = Y THEN 2200
2120 REM ILLEGAL IF WHITE AT Y
2130 FOR I2 = 1 TO 3
2140 IF W(I2) = Y THEN 2200
2150 NEXT I2
2160 IF L(X,Y) < >2 THEN 2200
2170 REM LEGAL MOVE FOR WHITE
2180 LET W(J2) = Y
2190 LET L2 = 1
2200 RETURN
3000 REM CALCULATE NEW WHITE POSITION NUMBER
3010 LET A3 = FN P(W(1)) + FN P(W(2)) + FN P(W(3))
3020 FOR S3 = 1 TO 165
3030 IF S(S3) = A3 THEN 3050
3040 NEXT S3
3050 RETURN
4000 REM PICK BLACK'S BEST MOVE
4010 LET M4 = 0
4020 FOR I4 = 1 TO 11
4030 IF L(B,I4) = 0 THEN 4110
4040 REM OCCUPIED BY WHITE?
4050 FOR J4 = 1 TO 3
4060 IF W(J4) = I4 THEN 4110
4070 NEXT J4
4075 IF M4 = 0 THEN 4100
4080 IF A(S3,M4) > = A(S3,I4) THEN 4110
4090 REM NEW BEST MOVE
4100 LET M4 = I4
4110 NEXT I4
4120 RETURN
6000 REM UPDATE AT GAME END
6010 FOR I6 = 1 TO I0 -1
6020 LET S = R(I6,1)
6030 LET M = R(I6,2)
6040 LET A(S,M) = A(S,M) +W
6050 NEXT I6
6060 RETURN
8999 REM DATA FOR L ARRAY
9000 DATA 0,2,2,2,0,0,0,0,0,0,0
9010 DATA 1,0,2,0,2,2,0,0,0,0,0
9020 DATA 1,2,0,2,0,2,0,0,0,0,0
9030 DATA 1,0,2,0,0,2,2,0,0,0,0
9040 DATA 0,1,0,0,0,2,0,2,0,0,0
9050 DATA 0,1,1,1,2,0,2,2,2,2,0
9060 DATA 0,0,0,1,0,2,0,0,0,2,0
9070 DATA 0,0,0,0,1,1,0,0,2,0,2
9080 DATA 0,0,0,0,0,1,0,2,0,2,2
9090 DATA 0,0,0,0,0,1,1,0,2,0,2
9100 DATA 0,0,0,0,0,0,0,2,2,2,0
9110 END
10000 REM <CTRL-J><CTRL-J>DRAW BOARD<CTRL-J><CTRL-J>
10010 GR
10020 COLOR= 1: FOR Y = 0 TO 39: HLIN 0,39 AT Y: NEXT Y
10030 COLOR= 3: FOR Y = 6 TO 10: HLIN 9,13 AT Y: HLIN 18,22 AT Y: HLIN 27,31 AT Y: NEXT Y
10040 FOR Y = 17 TO 21: HLIN 0,4 AT Y: HLIN 9,13 AT Y: HLIN 18,22 AT Y: HLIN 27,31 AT Y: HLIN 36,39 AT Y: NEXT Y
10050 FOR Y = 28 TO 32: HLIN 9,13 AT Y: HLIN 18,22 AT Y: HLIN 27,31 AT Y: NEXT Y
10060 HLIN 9,31 AT 8: HLIN 5,35 AT 19: HLIN 9,31 AT 30
10070 VLIN 8,30 AT 11: VLIN 8,30 AT 20: VLIN 8,30 AT 29
10080 Y = 19: FOR X = 1 TO 12: PLOT X,Y:Y = Y +1: NEXT X
10090 Y = 28: FOR X = 12 TO 19: PLOT X,Y:Y = Y -1: NEXT X
10100 Y = 19: FOR X = 19 TO 28: PLOT X,Y:Y = Y +1: NEXT X
10110 Y = 10: FOR X = 12 TO 19: PLOT X,Y:Y = Y +1: NEXT X
10120 Y = 19: FOR X = 19 TO 28: PLOT X,Y:Y = Y -1: NEXT X
10130 Y = 10: FOR X = 30 TO 37: PLOT X,Y:Y = Y +1: NEXT X
10140 Y = 19: FOR X = 1 TO 12: PLOT X,Y:Y = Y -1: NEXT X
10150 Y = 28: FOR X = 30 TO 37: PLOT X,Y:Y = Y -1: NEXT X
10160 COLOR= 15: GOSUB 11001: GOSUB 11002: GOSUB 11004
10170 COLOR= 0: GOSUB 11006
10180 RETURN
11000 REM SQUARE 1
11001 FOR Y3 = 18 TO 20: HLIN 1,3 AT Y3: NEXT Y3: RETURN
11002 FOR Y3 = 7 TO 9: HLIN 10,12 AT Y3: NEXT Y3: RETURN
11003 FOR Y3 = 18 TO 20: HLIN 10,12 AT Y3: NEXT Y3: RETURN
11004 FOR Y3 = 29 TO 31: HLIN 10,12 AT Y3: NEXT Y3: RETURN
11005 FOR Y3 = 7 TO 9: HLIN 19,21 AT Y3: NEXT Y3: RETURN
11006 FOR Y3 = 18 TO 20: HLIN 19,21 AT Y3: NEXT Y3: RETURN
11007 FOR Y3 = 29 TO 31: HLIN 19,21 AT Y3: NEXT Y3: RETURN
11008 FOR Y3 = 7 TO 9: HLIN 28,30 AT Y3: NEXT Y3: RETURN
11009 FOR Y3 = 18 TO 20: HLIN 28,30 AT Y3: NEXT Y3: RETURN
11010 FOR Y3 = 29 TO 31: HLIN 28,30 AT Y3: NEXT Y3: RETURN
11011 FOR Y3 = 18 TO 20: HLIN 37,39 AT Y3: NEXT Y3: RETURN
12000 REM INSTRUCTIONS
12010 HOME
12020 PRINT " 2----5----8"
12030 PRINT " /!\ ! /!\"
12040 PRINT " / ! \ ! / ! \"
12050 PRINT " / ! \ ! / ! \"
12060 PRINT " / ! \!/ ! \"
12070 PRINT " 1----3----6----9----11"
12080 PRINT " \ ! /!\ ! /"
12090 PRINT " \ ! / ! \ ! /"
12100 PRINT " \ ! / ! \ ! /"
12110 PRINT " \!/ ! \!/"
12120 PRINT " 4----7---10"
12130 POKE 34,11
12140 HOME
12150 PRINT " THE PLAYING FIELD FOR THE FRENCH"
12160 PRINT "MILITARY GAME IS SHOWN ABOVE. YOU WILL"
12170 PRINT "PLAY WHITE AND WILL START WITH THREE"
12180 PRINT "MEN LOCATED AT 1, 2, AND 4. BLACK HAS"
12190 PRINT "ONLY ONE MAN, WHICH STARTS AT 6. WHITE"
12200 PRINT "HAS THE FIRST MOVE AND MAY MOVE ANY ONE"
12210 PRINT "PIECE ONE SPACE."
12220 PRINT " WHITE MAY ONLY MOVE UP, DOWN, OR TO"
12230 PRINT "THE RIGHT. BLACK MAY MOVE IN ANY DIREC-"
12240 PRINT "TION. NO PIECE MAY MOVE TO A SPACE"
12250 PRINT "OCCUPIED BY ANOTHER PIECE."
12260 PRINT : PRINT " << PRESS THE SPACE BAR TO CONTINUE >>";
12270 IF PEEK( -16384) <127 THEN 12270
12280 POKE -16368,0
12290 HOME
12300 PRINT " WHITE WINS THE GAME BY PINNING THE"
12310 PRINT "BLACK PIECE SO THAT BLACK HAS NO MOVE."
12320 PRINT "THIS USUALLY OCCURS WITH BLACK TRAPPED"
12330 PRINT "AT 11, BUT IF BLACK PLAYS POORLY IT MAY"
12340 PRINT "BE PINNED AT 5 OR 7. BLACK WINS BY"
12350 PRINT "REACHING 1 OR BY EVADING BEING PINNED"
12360 PRINT "FOR 20 MOVES."
12370 PRINT " WHITE CAN ALWAYS WIN IF HE PLAYS"
12380 PRINT "CORRECTLY AND DOES NOT MAKE ANY MIS-"
12390 PRINT "TAKES. BUT IF YOU WANT TO RESIGN JUST"
12395 PRINT "TYPE 0,0"
12400 VTAB 24: PRINT " << PRESS THE SPACE BAR TO CONTINUE >>";
12410 IF PEEK( -16384) <127 THEN 12410
12415 POKE -16368,0
12420 HOME
12430 PRINT " THE GAME IS VERY EASY TO WIN THE"
12440 PRINT "FIRST FEW TIMES IT IS PLAYED, BUT IT"
12450 PRINT "WILL LEARN FROM ITS MISTAKES AND BECOME"
12460 PRINT "INCREASINGLY MORE DIFFICULT TO BEAT."
12470 PRINT " THE PROGRAM STORES WHAT IS HAS"
12480 PRINT "LEARNED IN AN ARRAY THAT MAY BE SAVED"
12490 PRINT "ON DISC OR TAPE."
12500 PRINT " IF THIS ARRAY IS NOT SAVED OR IS NOT"
12510 PRINT "RELOADED THE PROGRAM WILL START FROM"
12520 PRINT "THE BEGINNING IN LEARNING HOW TO PLAY"
12530 PRINT "EVERYTIME IT IS RUN."
12540 VTAB 24: PRINT " << PRESS THE SPACE BAR TO CONTINUE >>";
12550 IF PEEK( -16384) <127 THEN 12550
12560 POKE -16368,0
12570 TEXT : HOME
12580 RETURN